import { Config } from "../utils/config";
class Upload {
    constructor() {

    };
    /**
     * 执行上传
     * @param {上传的文件数组} files 
     */
    upload(files) {
        let uploadTasks = this.uploadTasks(files);
        return new Promise((resolve, reject) => {
            Promise.all(uploadTasks)
                .then(res => {
                    resolve(res);
                })
                .catch(err => {
                    reject(err);
                });
        });
    };
    /**
     * 上传任务队列
     * @param {上传文件} files 
     */
    uploadTasks(files) {
        let uploadTasks = files.map((file) => {
            return new Promise((resolve, reject) => {
                wx.uploadFile({
                    url: Config.baseUrl + '/gateway/api/system/upload',
                    filePath: file['url'],
                    name: "file",
                    formData: {},
                    success: (res) => {
                        resolve(res);
                    },
                    fail: (err) => {
                        reject(err);
                    }
                });
            });
        });
        return uploadTasks;
    }
}

export { Upload }